using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Reflection;


namespace ShoppingList
{
    public partial class InputBox : Form
    {
        public InputBox()
        {
            InitializeComponent();
        }

        private static InputBox inputBox = null;
        
        
        /// <summary>
        /// Shows the input box dialog and positions it based on sip input and screen size
        /// </summary>
        /// <param name="Prompt"></param>
        /// <param name="Title"></param>
        /// <param name="DefaultResponse"></param>
        /// <returns>the string entered by the user or String.Empty if cancel was pressed</returns>
        public static string Show(string Prompt, string Title, string DefaultResponse)
        {
            if (inputBox == null)
            {
                inputBox = new InputBox();
            }
            inputBox.promptLabel.Text = Prompt;
            inputBox.Text = Title;
            inputBox.lblCaption.Text = Title;
            inputBox.inputTextBox.Text = DefaultResponse;

            //show dialog in correct place on screen
            inputBox.Location = new Point((Screen.PrimaryScreen.Bounds.Width - inputBox.Width) / 2, (Screen.PrimaryScreen.Bounds.Height - inputBox.Height - inputBox.inputPanel1.Bounds.Height) / 2);
            inputBox.inputPanel1.Enabled = true;
            DialogResult res = inputBox.ShowDialog();
            inputBox.inputPanel1.Enabled = false;


            if (res == DialogResult.OK)
            {
                return inputBox.inputTextBox.Text;
            }
            else
            {
                return String.Empty;
            }
        }

        public static string Show(string Prompt)
        {
            return Show(Prompt, Assembly.GetExecutingAssembly().GetModules()[0].Name, String.Empty);
        }

        public static string Show(string Prompt, string Title)
        {
            return Show(Prompt, Title, String.Empty);
        }
    
    }


}